<template>
  <div class="housingDialog">
    <el-dialog title="房源管理" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="楼盘名称" :label-width="formLabelWidth">
          <el-input v-model="form.title" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="所属区域" :label-width="formLabelWidth">
          <el-input v-model="form.area" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="价格" :label-width="formLabelWidth">
          <el-input v-model="form.price" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="排序" :label-width="formLabelWidth">
          <el-input v-model="form.sort" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="Submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dialogFormVisible: false,
      form: {
        title: '',
        price: '',
        sort: '',
        area: ''
      },
      formLabelWidth: '120px'
    }
  },
  methods: {
    Submit () {
      if (this.form.id) {
        // 编辑
        this.$http.put('/housing/edit', this.form).then((res) => {
          if (res.data.code === 1) {
            this.$message.success(res.data.message)
          } else {
            this.$message.error(res.data.message)
          }
        })
      } else {
        // 添加
        this.$http.post('/housing/add', this.form).then((res) => {
          if (res.data.code === 1) {
            this.$message.success(res.data.message)
          } else {
            this.$message.error(res.data.message)
          }
        })
      }
      this.dialogFormVisible = false
    }
  }
}
</script>

<style>
</style>
